package com.yunc.modules.sys.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunc.base.controller.CommonController;
import com.yunc.common.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunc.modules.sys.entity.SysMailRetrieve;
import com.yunc.modules.sys.service.ISysMailRetrieveService;

/**
 * 邮件找回密码表 前端控制器
 *
 * @author concong tao
 * @since 2019-02-05
 */
@RestController
@RequestMapping("/sysMailRetrieve")
public class SysMailRetrieveController extends CommonController {

    @Autowired
    private ISysMailRetrieveService sysMailRetrieveService;

    @GetMapping("/page")
    public R page(Page<SysMailRetrieve> page, SysMailRetrieve sysMailRetrieve){
        sysMailRetrieveService.page(page, new QueryWrapper<>(sysMailRetrieve));
        return R.ok().put("data", page.getRecords()).put("count", page.getTotal());
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id){
        SysMailRetrieve sysMailRetrieve = sysMailRetrieveService.getById(id);
        return R.ok().put("sysMailRetrieve", sysMailRetrieve);
    }

    @PostMapping("/save")
    public R save(@RequestBody SysMailRetrieve sysMailRetrieve){
        boolean flag = sysMailRetrieveService.save(sysMailRetrieve);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @PutMapping(value = "/update")
    public R update(@RequestBody SysMailRetrieve sysMailRetrieve){
        boolean flag = sysMailRetrieveService.updateById(sysMailRetrieve);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        boolean flag = sysMailRetrieveService.removeById(id);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }
}
